var generate = function (arr) {
    return function () {
        let current = arr.shift()
        arr.push(current)
        return current
    }
}

const AsyncGenerate  = ({arr, cb} = {}) => {
    var g = generate(arr)
    var loop = function (echo, fn) {
        fn(echo(), function() {
            loop(echo, fn)
        })
    }
    return function () {
        loop(g, cb)
    }
}

var g1 = AsyncGenerate({
    arr: ['red','green','blue'],
    cb: function (num, cb) {
        setTimeout(() => {
            console.log(num)
            cb(null, num)
        }, 1000)
    }
})
g1()